package com.ccp.web.controller;

import org.apache.log4j.Logger;

import com.ccp.web.database.entity.User;
import com.ccp.web.service.af.ILoginManager;

public class LoginAction extends BaseAction {

	/**
	 * 
	 */
	private static final long serialVersionUID = 2576831910968466607L;

	static Logger logger;

	private String userName; 
	
	private String passWord;

	private ILoginManager loginManager;
	
	public ILoginManager getLoginManager() {
		return loginManager;
	}

	public void setLoginManager(ILoginManager loginManager) {
		this.loginManager = loginManager;
	}

	private User user;
	
	public LoginAction() {
		logger = Logger.getLogger(LoginAction.class.getName());
	}
	
	public String getUserName() {
		return userName;
	}

	public void setUserName(String userName) {
		this.userName = userName;
	}

	public String getPassWord() {
		return passWord;
	}

	public void setPassWord(String passWord) {
		this.passWord = passWord;
	}

	public User getUser() {
		return user;
	}

	public void setUser(User user) {
		this.user = user;
	}

	public String execute() throws Exception {
		logger.info("Strart login.");
		boolean flag = false;
		try {
			flag = loginManager.login(userName, passWord);
		} catch (Exception e) {
			e.printStackTrace();
		}
		if(flag == true){
			return SUCCESS;
		}else{
			return ERROR;
		}
	}
	
	public String init(){
		return SUCCESS;
	}
}
